package com.heima.article.service.impl;

import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * APP已发布文章配置表 服务实现类
 * </p>
 *
 * @author liu
 */
@Slf4j
@Service
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    //修改文章配置
    @KafkaListener(topics = "DownOrUp-topic")
    @Override
    public void updateByMap(Map map) {
        //0是上架 1是下架
        Object enable = map.get("enable");
        System.err.println(enable);
        boolean isDown = true;
        if (enable.equals(1)) {
            isDown =false;
        }
        update(Wrappers.<ApArticleConfig>lambdaUpdate()
                .eq(ApArticleConfig::getIsDown,map.get("articleId"))
                .set(ApArticleConfig::getIsDown,isDown)
        );

    }
}
